class rectangle { private int length,breadth; public void area() { int a=length*breadth; System.out.println("Area is "+a); } public void perimeter() { int p=2*(length+breadth); System.out.println("perimerter is"+p); } public void setdimension(int m,int n) { length=m; breadth=n; } } class demo { public static void main(String args[]) { rectangle a, b ; a = new rectangle(); b=new rectangle(); a.setdimension(5,7); b.setdimension(10,20); a.area(); a.perimeter(); b.area(); } }
Area is 35 Perimeter is 24 Area is 200
class Circle { private int radius; public void area() { double a=3.14*radius *radius; System.out.println("Area is "+a); } public void circumference() { double c=2*3.14*radius; System.out.println("circumference is"+c); } public void setRadius(int n) { radius=n; } } class demo { public static void main(String args[]) { Circle a; a=new Circle(); a.setRadius(5); a.area(); a.circumference(); } }
Area is 78.5 Circumference is 31.4
class Box { int L,B,H; public void volume() { int v=L*B*H; System.out.println("Volume is "+v); } public void setDimension(int x,int y,int z) { L=x; B=y; H=z; } } class demo { public static void main(String args[]) { Box a,b; a=new Box(); b=new Box(); a.setdimension(3,4,5); b.setdimension(7,8,2); a.volume(); b.volume(); } }
Volume is 60 Volume is 112
class Sphere { private int R; public void volume() { double V=4/3.0*3.14*R*R*R; System.out.println("Volume is "+v); } public void setRadius(int n) { R=n; } } class demo { public static void main(String args[]) { Sphere a; a=new Sphere(); a.setRadius(5); a.Volume(); } }
Volume is 523.3333
class Set { private int n1,n2,n3; public void sum() { int s=n1+n2+n3; System.out.println("Sum is "+s); } public void mean() { double m=(n1+n2+n3)/3.0; System.out.println("Mean is "+m); } public void setData(int x,int y,int z) { n1=x; n2=y; n3=z; } } class demo { public static void main(String args[]) { Set a,b; a=new Set(); b=new Set(); a.setData(4,5,7); b.setData(10,20,25); a.sum(); b.sum(); b.mean(); } }
Sum is 16 Sum is 55 Mean is 18.333333
class Worker { private String name; private int wages,wdays; public void showData() { System.out.println("Name is "+name); System.out.println("Wages is "+wages); System.out.println("Wdays are "+wdays); } public void payment( ) { int p=wages*wdays; System.out.println("Payment is "+p); } public void setData(String n,int w,int d) { name=n; wages=w; wdays=d; } } class demo { public static void main(String args[]) { Worker a; a=new Worker(); a.setData("Gopal",500,5); a.showData(); a.payment(); } }
Name is Gopal Wages is 500 Wdays are 5 Payment is 2500
class Account { private int accno,balance; public void interest(double r,int n) { double si=balance*r*n/100.0; System.out.println("Interest is "+si); } public void setData(int an,int bl) { accno=an; balance=bl; } } class demo { public static void main(String args[]) { Account a; a=new Account(); a.setData(44117,5000); a.interest(); } }
Interest is 2612.5